<?php
namespace Qy {
    /**
    * 企业微信菜单管理类
    * @author Jamers
    * @since 2017.1.1
    * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95
    */
    class Menu {
        private $common;
        public function __construct($ary = array()) {
            if (isset($ary['common'])) {
                $this->common = &$ary['common'];
            }else{
                $this->common = new \Qy\Common();
            }
        }
        /**
        * 创建应用菜单
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%9B%E5%BB%BA%E5%BA%94%E7%94%A8%E8%8F%9C%E5%8D%95
        * 
        * @param mixed $agentid
        * @param mixed $list
        * @param mixed $a_token
        */
        public function createMenu($agentid,$list=array(),$a_token='') {
            if (empty($list)||empty($agentid)) return false;
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token={$a_token}&agentid={$agentid}";
            return $this->common->httpRequest($url,$list,'post');
        }
        
        /**
        * 删除菜单
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E8%8F%9C%E5%8D%95
        * 
        * @param mixed $agentid
        * @param mixed $a_token
        */
        public function deleteMenu($agentid,$a_token='') {
            if (empty($agentid)) return false;
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?access_token={$a_token}&agentid={$agentid}";
            return $this->common->httpRequest($url);
        }
        
        /**
        * 获取菜单列表
        * @see http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E8%8F%9C%E5%8D%95%E5%88%97%E8%A1%A8
        * 
        * @param mixed $agentid
        * @param mixed $a_token
        */
        public function getMenuList($agentid,$a_token='') {
            if (empty($agentid)) return false;
            if (empty($a_token)) $a_token = $this->common->read_access_token();
            $url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token={$a_token}&agentid={$agentid}";
            return $this->common->httpRequest($url);
        }
    }
}
?>
